package com.laiyima.zhongjiang.linghuilv.demo.view;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.laiyima.zhongjiang.linghuilv.demo.R;
import com.lxj.xpopup.impl.PartShadowPopupView;

/**
 * Description:
 * Create by dance, at 2018/12/21
 */
public class MSShadowPopupView extends PartShadowPopupView {
    private Button b0, b1, b2, b3, b4;
    private int state;

    public MSShadowPopupView(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.ms_part_shadow_popup;
    }

    TextView text;

    @Override
    protected void onCreate() {
        super.onCreate();
        b0 = findViewById(R.id.mbutton_find0);
        b1 = findViewById(R.id.mbutton_find1);
        b2 = findViewById(R.id.mbutton_find2);
        b3 = findViewById(R.id.mbutton_find3);
        b4 = findViewById(R.id.mbutton_find4);
        Log.e("tag", "CustomPartShadowPopupView onCreate");
        b0.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                state=0;
                b0.setTextColor(Color.parseColor("#FFFFFFFF"));
                b0.setBackgroundResource(R.drawable.list_button_press);

                b1.setTextColor(Color.parseColor("#333333"));
                b1.setBackgroundResource(R.drawable.list_button);
                b2.setTextColor(Color.parseColor("#333333"));
                b2.setBackgroundResource(R.drawable.list_button);
                b3.setTextColor(Color.parseColor("#333333"));
                b3.setBackgroundResource(R.drawable.list_button);
                b4.setTextColor(Color.parseColor("#333333"));
                b4.setBackgroundResource(R.drawable.list_button);
                dismiss();
             }
        });
        b1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                state=1;
                b1.setTextColor(Color.parseColor("#FFFFFFFF"));
                b1.setBackgroundResource(R.drawable.list_button_press);
                b0.setTextColor(Color.parseColor("#333333"));
                b0.setBackgroundResource(R.drawable.list_button);
                b2.setTextColor(Color.parseColor("#333333"));
                b2.setBackgroundResource(R.drawable.list_button);
                b3.setTextColor(Color.parseColor("#333333"));
                b3.setBackgroundResource(R.drawable.list_button);
                b4.setTextColor(Color.parseColor("#333333"));
                b4.setBackgroundResource(R.drawable.list_button);
                dismiss();
            }
        });
        b2.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                state=2;
                b2.setTextColor(Color.parseColor("#FFFFFFFF"));
                b2.setBackgroundResource(R.drawable.list_button_press);
                b0.setTextColor(Color.parseColor("#333333"));
                b0.setBackgroundResource(R.drawable.list_button);
                b1.setTextColor(Color.parseColor("#333333"));
                b1.setBackgroundResource(R.drawable.list_button);
                b3.setTextColor(Color.parseColor("#333333"));
                b3.setBackgroundResource(R.drawable.list_button);
                b4.setTextColor(Color.parseColor("#333333"));
                b4.setBackgroundResource(R.drawable.list_button);
                dismiss();
            }
        });
        b3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                state=3;
                b3.setTextColor(Color.parseColor("#FFFFFFFF"));
                b3.setBackgroundResource(R.drawable.list_button_press);
                b0.setTextColor(Color.parseColor("#333333"));
                b0.setBackgroundResource(R.drawable.list_button);
                b1.setTextColor(Color.parseColor("#333333"));
                b1.setBackgroundResource(R.drawable.list_button);
                b2.setTextColor(Color.parseColor("#333333"));
                b2.setBackgroundResource(R.drawable.list_button);
                b4.setTextColor(Color.parseColor("#333333"));
                b4.setBackgroundResource(R.drawable.list_button);
                dismiss();
            }
        });
        b4.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                state=4;
                b4.setTextColor(Color.parseColor("#FFFFFFFF"));
                b4.setBackgroundResource(R.drawable.list_button_press);
                b0.setTextColor(Color.parseColor("#333333"));
                b0.setBackgroundResource(R.drawable.list_button);
                b1.setTextColor(Color.parseColor("#333333"));
                b1.setBackgroundResource(R.drawable.list_button);
                b2.setTextColor(Color.parseColor("#333333"));
                b2.setBackgroundResource(R.drawable.list_button);
                b3.setTextColor(Color.parseColor("#333333"));
                b3.setBackgroundResource(R.drawable.list_button);
                dismiss();
            }
        });
    }

    @Override
    protected void onShow() {
        super.onShow();
        Log.e("tag", "CustomPartShadowPopupView onShow");
    }

    @Override
    protected void onDismiss() {
        SharedPreferences sharedPreferences = getContext().getSharedPreferences("userinfo.txt", Context.MODE_PRIVATE); //私有数据
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt("machine_state",state);
        editor.commit();
        super.onDismiss();
    }
}
